package cn.cheneyjoo.sqlsession;

import cn.cheneyjoo.config.XMLConfigBuilder;
import cn.cheneyjoo.model.Configuration;
import org.dom4j.DocumentException;

import java.io.InputStream;

public class SqlSessionFactoryBuilder {
    public SqlSessionFactory build(InputStream in) throws DocumentException {
        // 1.使用dom4j解析SQL信息配置文件，解析配置文件内容并封装到Configuration对象容器中
        XMLConfigBuilder xmlConfigBuilder = new XMLConfigBuilder();
        Configuration configuration = xmlConfigBuilder.parseConfig(in);
        // 2.创建SqlSessionFactory对象
        DefaultSqlSessionFactory defaultSqlSessionFactory = new DefaultSqlSessionFactory(configuration);

        return defaultSqlSessionFactory;
    }
}
